<template>
	<view class="content padding">
		<view class="padding ffffff border">
			<view class="text_x color_ling">
				抬头类型
			</view>
			<view class="margin_top flexleft">
				<view :class="invoice_title_type==1?'select padding45 margin_right3':'noSelect padding45 margin_right3'"
					@click="invoice_title_type=1">
					个人
				</view>
				<view :class="invoice_title_type==2?'select padding45':'noSelect padding45'"
					@click="invoice_title_type=2">
					单位
				</view>
			</view>
		</view>
		<view class="padding ffffff margin_top flexbetween border">
			<view class="text_x color_ling margin_right6">
				发票抬头
			</view>
			<input class="flex1 textright text_a" type="text" placeholder="请输入发票抬头"
				placeholder-style="font-size: 28rpx;font-weight: 500;color: #666666;" v-model="invoice_title">
		</view>
		<view v-if="invoice_title_type==2">
			<view class="padding ffffff margin_top flexbetween border">
				<view class="text_x color_ling margin_right6">
					单位税号
				</view>
				<input class="flex1 textright text_a" type="text" placeholder="请输入单位税号"
					placeholder-style="font-size: 28rpx;font-weight: 500;color: #666666;" v-model="duty_paragraph">
			</view>
			<view class="padding ffffff margin_top flexbetween border">
				<view class="text_x color_ling margin_right6">
					开户银行
				</view>
				<input class="flex1 textright text_a" type="text" placeholder="请输入开户银行"
					placeholder-style="font-size: 28rpx;font-weight: 500;color: #666666;" v-model="bank_name">
			</view>
			<view class="padding ffffff margin_top flexbetween border">
				<view class="text_x color_ling margin_right6">
					银行账号
				</view>
				<input class="flex1 textright text_a" type="number" placeholder="请输入银行账号"
					placeholder-style="font-size: 28rpx;font-weight: 500;color: #666666;" v-model="bank_code">
			</view>
			<view class="padding ffffff margin_top flexbetween border">
				<view class="text_x color_ling margin_right6">
					单位地址
				</view>
				<input class="flex1 textright text_a" type="text" placeholder="请输入单位地址"
					placeholder-style="font-size: 28rpx;font-weight: 500;color: #666666;" v-model="address">
			</view>
			<view class="padding ffffff margin_top flexbetween border" style="margin-bottom: 100rpx;">
				<view class="text_x color_ling margin_right6">
					单位电话
				</view>
				<input class="flex1 textright text_a" type="number" placeholder="请输入单位电话"
					placeholder-style="font-size: 28rpx;font-weight: 500;color: #666666;" v-model="tel">
			</view>
		</view>
		<view class="footer ffffff padding">
			<view class="footerButton" @click="submit">
				保存
			</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				id: "", //编辑id
				invoice_title: "", //发票抬头
				invoice_title_type: 1, // 1个人 2单位
				duty_paragraph: "", //税号
				bank_name: "", //开户行
				bank_code: "", //企业账号
				address: "", //企业地址
				tel: "", //企业电话
			}
		},
		onLoad(options) {
			if(options.id){
				this.id = options.id
				uni.setNavigationBarTitle({
					title:"编辑发票抬头"
				})
				this.getInfo()
			}
		},
		methods: {
			getInfo(){
				let _this = this;
				httpRequest.request('/api/invoice/detail', 'GET', {
					id:_this.id,//编辑id
				}, false, false, true).then(res => {
					if (res.code == 1) {
						// httpRequest.toast(res.msg);
						this.invoice_title=res.data.invoice_title
						this.invoice_title_type=res.data.invoice_title_type
						this.duty_paragraph=res.data.duty_paragraph
						this.bank_name=res.data.bank_name
						this.bank_code=res.data.bank_code
						this.address=res.data.address
						this.tel=res.data.tel
					}else{
						httpRequest.toast(res.msg);
					}
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			submit(){
				let _this = this;
				httpRequest.request('/api/invoice/edit', 'POST', {
					id:_this.id,//编辑id
					invoice_title:_this.invoice_title,//发票抬头
					invoice_title_type:_this.invoice_title_type,//发票抬头类型:1=个人,2=企业
					duty_paragraph:_this.duty_paragraph,//税号
					bank_name:_this.bank_name,//开户行
					bank_code:_this.bank_code,//企业账号
					address:_this.address,//企业地址
					tel:_this.tel,//企业电话
				}, false, false, true).then(res => {
					if (res.code == 1) {
						httpRequest.toast(res.msg);
						setTimeout(()=>{
							uni.navigateBack(1)
						},500)
					}else{
						httpRequest.toast(res.msg);
					}
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.noSelect {
		padding: 18rpx 20rpx;
		text-align: center;
		background: rgba(102, 102, 102, .1);
		border-radius: 8rpx 8rpx 8rpx 8rpx;
		border: 2rpx solid rgba(102, 102, 102, .1);
		font-size: 24rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #666666;
	}

	.select {
		padding: 18rpx 20rpx;
		text-align: center;
		background: rgba(243, 39, 28, 0.1);
		border-radius: 8rpx 8rpx 8rpx 8rpx;
		border: 2rpx solid #F3271C;
		font-size: 24rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #F3271C;
	}
</style>